﻿#region

using System.Windows.Media;

#endregion

namespace HudsonMonitor
{
    public static class Utilities
    {
        /// <summary>
        ///   Helper method to get a color based on it's string value
        /// </summary>
        /// <param name = "colorString">The name of the string, for example red</param>
        /// <returns>A brush with the color, bla</returns>
        public static Brush StringToBrush(string colorString)
        {
            Brush returnValue = Brushes.Black;

            if (!string.IsNullOrEmpty(colorString))
            {
                string tempString = colorString.ToLower().Trim();
                if (tempString.EndsWith("_anime"))
                    tempString = tempString.Replace("_anime", "");

                switch (tempString)
                {
                    case "grey":
                        returnValue = Brushes.Gray;
                        break;
                    case "red":
                        returnValue = Brushes.Red;
                        break;
                    case "blue":
                        returnValue = Brushes.Green;
                        break;
                }
            }

            return returnValue;
        }

        /// <summary>
        ///   Converts a color to a status
        /// </summary>
        /// <param name = "colorString">The hudson statuscolor</param>
        /// <returns>The status</returns>
        public static Status StringToStatus(string colorString)
        {
            Status returnValue = Status.Ok;

            if (!string.IsNullOrEmpty(colorString))
            {
                string tempString = colorString.ToLower().Trim();
                if (tempString.EndsWith("_anime"))
                    tempString = tempString.Replace("_anime", "");

                switch (tempString)
                {
                    case "grey":
                        returnValue = Status.Unstable;
                        break;
                    case "red":
                        returnValue = Status.Failed;
                        break;
                    case "blue":
                        returnValue = Status.Ok;
                        break;
                }
            }

            return returnValue;
        }

        /// <summary>
        ///   Converts a status to at massage
        /// </summary>
        /// <param name = "status">The hudson statuscolor</param>
        /// <returns>The status</returns>
        public static string StatusToString(string status)
        {
            string returnValue = "";

            if (!string.IsNullOrEmpty(status))
            {
                string tempString = status.ToLower().Trim();
                if (tempString.EndsWith("_anime"))
                    tempString = tempString.Replace("_anime", "");

                switch (tempString)
                {
                    case "grey":
                        returnValue = "Ustabile";
                        break;
                    case "red":
                        returnValue = "Failed";
                        break;
                    case "blue":
                        returnValue = "Ok";
                        break;
                    default:
                        returnValue = "Unknown";
                        break;
                }
            }

            return returnValue;
        }
    }
}